package com.etc.controller;

import com.etc.pojo.Favorite;
import com.etc.pojo.User;
import com.etc.service.FavoritePersonageService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("FavoritePersonageController")
public class FavoritePersonageController {

    @Autowired
    FavoritePersonageService FavoritePersonage;

    @ResponseBody
    @RequestMapping(value = "queryAllFavoriteByUserId")
    public PageInfo<Favorite> queryAllFavoriteByUserId(@RequestParam(value = "pageNum", defaultValue = "1")  Integer pageNum,
                                                       HttpSession session) {
        User user = (User)session.getAttribute("user");
        PageInfo<Favorite> pageInfo = FavoritePersonage.queryAllFavoriteByUserId(user.getUserId(),pageNum);
        return pageInfo;
    }

    @ResponseBody
    @RequestMapping(value = "deleteFavoriteByVideoId")
    public boolean deleteFavoriteByVideoId(@RequestParam(value = "favoriteId")  Integer favoriteId) {
        boolean leep = FavoritePersonage.deleteFavoriteByVideoId(favoriteId);
        return leep;
    }
}
